package com.jkj.http.controller;

import com.jkj.http.entity.ResultType;
import com.jkj.utils.JsonUtils;

import java.util.HashMap;
import java.util.Map;

public class BaseController {
    protected String success() {
        return success("恭喜您，操作成功。");
    }

    protected String success(String message) {
        return success(message, null);
    }

    protected String success(String message, String data) {
        Map<String, Object> map = new HashMap<>();
        map.put("state", ResultType.Success);
        map.put("message", message);
        map.put("data", data);
        return JsonUtils.toJSON(map);
    }

    protected String error() {
        return error("对不起，操作失败。");
    }

    protected String error(String message) {
        return error(message, null);
    }

    protected String error(String message, Object data) {
        Map<String, Object> map = new HashMap<>();
        map.put("state", ResultType.Error);
        map.put("message", message);
        map.put("data", data);
        return JsonUtils.toJSON(map);
    }


    protected String warning(String message) {
        return warning(message, null);
    }

    protected String warning(String message, Object data) {
        Map<String, Object> map = new HashMap<>();
        map.put("state", ResultType.Warning);
        map.put("message", message);
        map.put("data", data);
        return JsonUtils.toJSON(map);
    }

    protected String info(String message) {
        return info(message, null);
    }

    protected String info(String message, Object data) {
        Map<String, Object> map = new HashMap<>();
        map.put("state", ResultType.Info);
        map.put("message", message);
        map.put("data", data);
        return JsonUtils.toJSON(map);
    }
}
